package proxy;


import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MethodTest {
    public static void getMethod() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        UserServiceImpl userService = new UserServiceImpl();
        Method getName = userService.getClass().getMethod("getName");
        Object invoke = getName.invoke(userService);
        System.out.println(invoke);
    }
    public static void getAge() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        UserServiceImpl userService = new UserServiceImpl();
        Method getName = userService.getClass().getMethod("getAge", Integer.class);
        Object invoke = getName.invoke(userService,25);
        System.out.println(invoke);
    }

    public static void getNameAndAge() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        UserServiceImpl userService = new UserServiceImpl();
        Method getNameAndAge = userService.getClass().getMethod("getNameAndAge", String.class, Integer.class);
        // 输出：fangqing的年龄为：24
        getNameAndAge.invoke(userService,"fangqing",24);
    }
}
